package com.cly.user.controller;

import com.cly.common.entity.result.Result;
import com.cly.common.entity.user.dto.UserLoginDTO;
import com.cly.common.entity.user.dto.UserRegisterDTO;
import com.cly.common.entity.user.vo.UserLoginVO;
import com.cly.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 验证码登录
     * @param userLoginDTO
     */
    @PostMapping("/login/authCode")
    public Result<UserLoginVO> loginAuthCode(@RequestBody UserLoginDTO userLoginDTO) {
        return userService.loginAuthCode(userLoginDTO);
    }

    /**
     * 密码登录
     * @param userLoginDTO
     * @return
     */
    @PostMapping("/login/password")
    public Result<UserLoginVO> loginPassword(@RequestBody UserLoginDTO userLoginDTO) {
        return userService.loginPassword(userLoginDTO);
    }

    /**
     * 注册(使用手机号验证码)
     * @param userRegisterDTO
     * @return
     */
    @PostMapping("/register/phone")
    public Result register(@RequestBody UserRegisterDTO userRegisterDTO) {
        return userService.registerByPhone(userRegisterDTO);
    }

    /**
     * 扣减余额
     * @param password
     * @param amount
     */
    @PutMapping("/deduct/money")
    public void deductMoney(@RequestParam String password, @RequestParam Integer amount){
        userService.deductMoney(password, amount);
    }
}
